import { produce } from 'immer';
import { DesignInfo } from 'src/modules';
import { CanvasActions } from './actions';
import { ActionType } from './types';

export interface CanvasState {
  designs: DesignInfo[];
}

const initialState: CanvasState = {
  designs: [],
};

export default (state = initialState, action: CanvasActions): CanvasState => {
  switch (action.type) {
    case ActionType.LoadDesignsDone:
      return produce(state, (draft) => {
        draft.designs = action.payload;
      });
    default:
      return state;
  }
};
